<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<html>
<head>
    <title>回复</title>
    <link rel="stylesheet" rel="stylesheet" href="/static/css/post.css">
    <script type="text/javascript" src="/static/js/jquery-3.4.1.js"></script>

</head>
<body>
<jsp:include page="head.jsp"/>
<div class="b-body">
    <div align="center" class="f-center">
        <table border="1" width="47%" height="250" style="border-width: 0px;">
            <tr>
                <td style="border-style: none; border-width: medium">
                    <form class="contact_form" id="form">
                        <ul>
                            <li>
                                <h2>回复</h2>
                            </li>
                            <li>
                                <label>内容:</label>
                                <textarea name="replyContent" cols="40" rows="10" placeholder="内容" required
                                ></textarea>
                            </li>
                            <li>
                                <label>图片</label>
                                <input type="file" id="imageFile" name="file" accept="image/jpeg"/>
                            </li>
                            <input type="hidden" value="${user.userId}" name="userId">
                            <input type="hidden" value="${post.postId}" name="postId">
                            <li>
                                <button class="submit" type="button" onclick="sendAjax()">回复</button>
                                <button class="submit" type="reset">清空</button>
                            </li>
                        </ul>
                    </form>
                </td>
            </tr>
        </table>
    </div>
</div>
</body>
<script>
    function sendAjax() {

        $.ajax({
            url: '/reply',
            type: 'POST',
            data: new FormData($('#form')[0]),
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            // dataType:FormData,
            success: function (data) {
                alert(data.info)
                if (data.info == "回复成功") {
                    window.location.href = "postContent?postId=${post.postId}";
                }
            },
            error: function () {
                alert("请求出错")
            },
            complete: function () {
            }
        })
    }
</script>
</html>